<?php 
require_once 'common/common.inc.php';
require_once 'common/mail.inc.php';

$date_str = isset($_REQUEST["date_str"]) ? $_REQUEST["date_str"] : "";
$reservation_id = isset($_REQUEST["reservation_id"]) ? $_REQUEST["reservation_id"] : "";
$guid = isset($_REQUEST["guid"]) ? $_REQUEST["guid"] : "";
$error = isset($_REQUEST["error"]) ? $_REQUEST["error"] : "";

if (!isset($_REQUEST["redirect"])) 
{
  conn();
  
  // confirm reservation
  $sql = "";
  $sql .= "UPDATE RESERVATIONS ";
  $sql .= " SET PAID = 1  ";
  $sql .= "WHERE ID = '$reservation_id' ";
  $sql .= "AND GUID = '$guid' ";
  //echo $sql;
  
  $result = mysql_query($sql);
  if (!$result) {die('Could not exec query: ' . mysql_error());}

  $sql = "";
  $sql .= "SELECT r.ID, r.START, r.SIGN_IN_EMAIL, CAST(r.CONFIRMED AS unsigned int) CONFIRMED, CAST(r.PAID AS unsigned int) PAID, rcw.ITEM_NR ";
  $sql .= "FROM RESERVATIONS r ";
  $sql .= "  INNER JOIN RESERVATIONS_CAR_WASH rcw ON r.ID = rcw.RESERVATION_ID ";
  $sql .= "WHERE r.ID = '$reservation_id' ";
  $sql .= "AND r.GUID = '$guid' ";
  //echo $sql;
  
  $result = mysql_query($sql);
  if (!$result) {die('Could not exec query: ' . mysql_error());}
  $row = mysql_fetch_array($result, MYSQL_ASSOC);
  
  if (isset($row["START"]) && $row["START"] != null) {
  
    $start = strtotime( $row["START"] );
    $reservation_date = new DateTimeDutch("@".$start, $timezone);
    $reservation_date->setTimezone($timezone); 
    $date_str = $reservation_date->format('l d F Y');
    $paid = $row["PAID"];
    //echo $paid;
    
    $auto_wassen_pakket = $row["ITEM_NR"];
  } 
  else 
  {
    $error = "De betaling is succesvol uitgevoerd. ";
    $error .= "Maar is niet correct verwert in de Red Je Zaterdag administratie! ";
  }
  close();
  
  // redirect to the same page without the POST data
  header("Location: ".$_SERVER['PHP_SELF']."?redirect=redirect&date_str=$date_str&reservation_id=$reservation_id&guid=$guid&error=$error&paid=$paid");
  die;
}

?>

<?php 
include 'common/page.begin.inc.php';
?>

<body>

<div id="wrapper">

  <?php 
  $menuSelected = "diensten";
  $subMenuSelected = "auto-wassen";
  include 'common/body.header.inc.php';
  ?>

  <div id="page" class="container">
  
    <div id="content">

      <?php
      $contentPath = "Auto wassen &gt;&gt; Afspraak Maken";
      include 'common/body.content.header.inc.php';
      ?>
      
      <div class="main-top">
        <div class="first auto-wassen">
        </div>  
        <div class="second">
          <div class="content-blok" style="position:relative">

            <?php 
            include 'common/body.error.inc.php';
            ?>

            <?php if (empty($error)) { ?>

              <p>
                <h2>De reservering is met succes betaald</h2>
              </p>

              <p>
                <?php echo $date_str; ?>.
              </p>
            
              <?php 
              //$vcs_link_page = "26_reservation_vcs.php";
              //include 'common/outlook.link.php';
              ?>
                
            <?php } ?>
        
          </div><!-- end content blok -->  
        </div><!-- end second -->  
      </div><!-- end home top -->

    </div><!-- end content -->

    <div style="clear: both;"></div>
	</div><!-- end page -->  
  
  <?php 
  include 'common/body.footer.inc.php';
  ?>
  
</div><!-- end wrapper -->

<?php 
include 'common/page.end.inc.php';
?>


